using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Media.Imaging;

namespace MicroFractal.iTunesBrowser.Business
{
    /// <summary>
    /// Representa el Album de un artista.
    /// </summary>
    public class Album : IDownloadableObject
    {

        #region Constructors

        public Album(string name)
        {
            _name = name;
            _songs = new List<Song>();
        }

        public Album(string name, Artist artist)
            : this(name)
        {
            _artist = artist;

            if (!artist.Albums.Contains(this))
                artist.Albums.Add(this);
        }

        #endregion

        #region Properties

        private string _name;
        /// <summary>
        /// Obtiene o establece el nombre del album.
        /// </summary>
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        private Artist _artist;
        /// <summary>
        /// Obtiene o establece el artista del album
        /// </summary>
        public Artist Artist
        {
            get { return _artist; }
            set { _artist = value; }
        }

        private List<Song> _songs;

        public List<Song> Songs
        {
            get { return _songs; }
            set { _songs = value; }
        }

        private BitmapImage _cover;
        /// <summary>
        /// Obtiene o establece la tapa del album.
        /// </summary>
        public BitmapImage Cover
        {
            get { return _cover; }
            set { _cover = value; }
        }

        #endregion

        #region Overrides

        public override bool Equals(object obj)
        {
            if (obj != null && obj is Album)
            {
                Album a = (Album)obj;
                if (_name == a._name)
                {
                    if (a._artist != null && _artist != null)
                    {
                        return _artist.Equals(a._artist);
                    }
                    else
                        return a._artist == _artist;
                }

            }
            return false;
        }

        public override string ToString()
        {
            return _name;
        }

        #endregion

        #region IDownloadableObject Members

        public IList<Song> GetDownloadableSongs()
        {
            return this._songs;
        }

        #endregion
    }
}
